package com.juc.concurrency.jucExample.threadLocal.example;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * ThreadLocalExample
 */
public class ThreadLocalExample implements Runnable{
    private static AtomicInteger counter = new AtomicInteger(100);
    private static ThreadLocal<String> threadInfo = new ThreadLocal<String>() {
        @Override
        protected String initialValue() {
            return "[" + Thread.currentThread().getName() + "," + counter.getAndIncrement() + "]";
        }
    };

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new ThreadLocalExample());
        Thread thread2 = new Thread(new ThreadLocalExample());

        thread1.start();
        thread2.start();

  //     thread1.join();
//        thread2.join();

        System.out.println("threadInfo value in main:" + threadInfo.get());
    }

    @Override
    public void run() {
        System.out.println("threadInfo value:" + threadInfo.get());
    }
}
